import axios from 'axios';
const isNewVersion = () => {
    let pathname = "";
    if (window.location.pathname.includes("/index.html")) {
        pathname = window.location.pathname.split("/index.html")[0];
    } else {
        pathname = window.location.pathname;
    };
    let url = `${window.location.origin + pathname}/version.json?t=${new Date().getTime()}`;
    axios({
        method: "get",
        url,
    }).then((res) => {
        if (res.status == 200) {
            let version = res.data.version;
            let localVersion = localStorage.getItem("localVersion");

            localStorage.setItem("localVersion", version);

            if (!localVersion || localVersion != version) {
                window.location.reload(true);
                return;
            }
        }
    }).catch((err) => {

    });
};


export default {
    isNewVersion
}
